home *** CD-ROM | disk | FTP | other *** search
- /*
- File: "how to call AutoPay.c"
-
- Last updated 4/20/96
-
- This file implements a simple application demonstrating how to use
- Release Software's AutoPay™ code resource in your own application.
-
- This source code should run unmodified on both MetroWerks CodeWarrior C/C++
- and Symantec Think C compilers. Pascal development environments are also
- supported in supplementary files.
-
- What is this?: This is a meaningless app that puts up a window, waits
- for you to press a button, then launches the AutoPay
- module. When the AutoPay module is finished running,
- this mini-app puts up a final window. To actually
- run this, you'll need to include the AutoPay.rsrc
- file in your project, along with the minimal
- resource set this mini-app uses. We've thoughtfully
- included those resources in the file "how to call.π.rsrc".
-
- To build this project: To build this project, include the "how to call.π.rsrc",
- the AutoPay.rsrc file, an ANSI C library
- (2-byte integers; in MetroWerks look for ANSI (2i/f) C.A5),
- and this source code file.
-
- Tech Support: If you're a developer and you need technical support, we'll
- be glad to help. We also welcome your comments, suggestions,
- and gripes.
-
- Technical support: (415) 833-0200
- matthew@releasesoft.com
-
-
- Sales and info: (800) 210-5517
- info@releasesoft.com
- */
-
- #include "DMIdeveloper.h.c"
- #include <string.h>
-
- typedef pascal long (*AutoPayCodePtr) (long);
-
- void ToolBoxInit (void);
- void InitAutoPay(digiMonBlock *myDMCB);
- void DoAutoPay(digiMonBlock *dmiBlock);
-
- digiMonBlock gDMCB;
-
- /*
- Function: main
-
- Calls InitAutoPay() to fill in the struct that we pass to the AutoPay
- code resource. Calls DoAutoPay to execute the resource.
-
- Returns: Nothing.
- */
-
- void main (void)
- {
-
- // Set the app up
- ToolBoxInit();
- ParamText("\pPress OK to launch the AutoPay code resource.", "\p", "\p", "\p");
- NoteAlert(129, nil);
-
-
-
- // Fill in the AutoPay Control Block
- InitAutoPay(&gDMCB);
-
- // Execute the code resource using our DMCB
- DoAutoPay(&gDMCB);
-
- // Shut the app down
- ParamText("\pCode resource finished executing.", "\p", "\p", "\p");
- NoteAlert(129, nil);
- ExitToShell();
- }
-
- /*
- Function: ToolBoxInit
-
- The usual suspects.
-
- Returns: Nothing.
- */
-
- void ToolBoxInit(void)
- {
- InitGraf((Ptr) &qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- FlushEvents(everyEvent,0);
- TEInit();
- InitDialogs(0L);
- InitCursor();
- }
-
- /*
- Function: InitAutoPay
-
- Fills in the digiMonBlock struct with info appropriate for our sample product.
- Although this sample app doesn't do it, be sure to deallocate any memory allocated
- by this function after your call to DoAutoPay().
-
- Returns: Filled in struct in the myDMCB parameter
- */
-
- void InitAutoPay(digiMonBlock *myDMCB)
- {
- short i;
-
- // General settings
-
- strcpy(myDMCB->programName, "Testbed 1.0");
- myDMCB->returnSerialNum = 1; // 1=true; 0=false
- myDMCB->areAdditionalItemsForSale = 1; // 1=true; 0=false
- strcpy(myDMCB->programPassword, "tempPassword");
- strcpy(myDMCB->programID, "123456");
- strcpy(myDMCB->programSource, "CIS");
-
-
- // Security
-
- // This is a secret string of ascii characters used for encryption.
- // You should keep this key confidential, even among your own employees.
- // The string is comprised of visible ASCII characters - i.e. don't
- // use control characters. But punctuation is okay.
-
- strcpy(myDMCB->encodeMeth, "sampleEncodeUseYourOwn");
-
- // Screen Text
-
- // You can alter the text that appears on the top of each dialog box displayed
- // by AutoPay. Normally, AutoPay reads "styled text" resources
- // from your resource file, but if you want to change the text on the fly, so
- // to speak, you can just pass a pointer leading to the appropriate
- // text and style handle. Note that you must first initialize all 10 text pointers
- // to zero so that AutoPay can tell the difference between a zero pointer
- // (i.e. you don't want to replace the default text in the resource file) and a
- // non-zero pointer (you *do* want to change the text). See below for an example.
-
- for (i=0; i<=9; i++) {
- myDMCB->screenText[i] = 0;
- }
-
- // Next be sure to allocate memory for any pointer that you want AutoPay
- // to use. For instance, to change the text that appears on the opening screen,
- // set the screenText[0] pointer, like this:
-
-
- myDMCB->screenText[0] = NewPtr(200);
- myDMCB->screenText[0] = "AutoPay is embedded in a test application.\rBelow, select how you want to pay.";
- myDMCB->textSize[0] = 10;
- myDMCB->textFont[0] = applFont;
-
-
- // ...for a complete list of which array item corresponds to which dialog,
- // see printed docs.
-
- // The users name
-
- // If you already know the users name for some reason, you should send it
- // to the DM Module, so that DM doesn't have to ask the user for it. If you
- // don't know it, then **be sure** to set the usersName string to null. In
- // any case, if the user successfully completes enough of the DM transaction,
- // his name will be returned to you in this string, should you want to use it,
- // for registration splash screens or whatever.
-
- strcpy(myDMCB->usersName, ""); // I don't know it, so it to null!
-
-
- // Software "switches"
-
- // AutoPay is continually being upgraded to add new features. You can turn new
- // features on and off by using a series of software "switches", which are set
- // through the "privateKey" field. The format of this field is: the asterisk
- // character ('*') followed by a series of 1's and 0's representing whether a
- // a switch (and thus a particular feature) is turned on or off. Currently you
- // can access two software switches, but six more are slated for future use.
- //
- // The format is:
- //
- // Character Description
- // ========= ===========
- // 0 always "*"
- // 1 0 = voice telephone ordering is selectable by the user
- // 1 = voice telephone ordering is disabled
- // 2 0 = no long product descriptions are avaiable
- // 1 = long product descriptions are avaiable starting at
- // TEXT resource 3040 (description of catalogItem[0])...
- // 3 1 = Email address required of user.
- // 0 = No it's not.
- // 4 1 = User can change quantity of things on purchase list, but cannot remove item
- // completely from shopping list. This is useful only in very rare cases when you preselect
- // the users shopping list for him and need to ensure he doesn't try to "cheat" by getting
- // a package deal price for the wrong items.
- // 0 = No such restriction. User can change quantity of things on shopping list, assuming it's
- // within minPurchase and maxPurchase parameters you set.
-
- strcpy(myDMCB->privateKey, "*00000000");
-
-
- // Your Product Catalog
-
- // Product names are generally short.
- // If you want to include "long" product descriptions, use the software switch
- // below and be sure to include one TEXT resource for every product in your
- // catalog, starting with resource #3040 (for catalogItem[0]). See the Manual
- // Addendum for more info.
-
- myDMCB->numItemsInCatalog = 3;
-
- // first, initialize pointers for each item in catalog
- // notice first item is item #0
-
- for (i= 0; i <= myDMCB->numItemsInCatalog - 1; i++) {
- myDMCB->catalogItem[i] = (catalogItemType *)NewPtr(sizeof(catalogItemType));
- }
-
-
- strcpy(myDMCB->catalogItem[0]->name, "Register Testbed 1.0");
- // registration items (if the item to be bought is the actual program in
- // which AutoPay is embedded), have product codes that start with 9
- strcpy(myDMCB->catalogItem[0]->prodCode, "90001");
- myDMCB->catalogItem[0]->minPurchase = 1;
- myDMCB->catalogItem[0]->maxPurchase = 1;
- myDMCB->catalogItem[0]->price = 15.50;
- myDMCB->catalogItem[0]->numVarCodes = 0;
- // Notice how you have to set shipping and handling charges (both domestic
- // and foreign) even if they're zero!
- myDMCB->catalogItem[0]->shUSA = 0;
- myDMCB->catalogItem[0]->shFOR = 0;
-
- strcpy(myDMCB->catalogItem[1]->name, "AutoPay tee-shirt");
- // physical goods that need to be delivered to the purchaser have product codes
- // that start with 7
- strcpy(myDMCB->catalogItem[1]->prodCode, "70002");
- myDMCB->catalogItem[1]->minPurchase = 1;
- myDMCB->catalogItem[1]->maxPurchase = 10;
- myDMCB->catalogItem[1]->price = 20;
- myDMCB->catalogItem[1]->numVarCodes = 2;
- strcpy(myDMCB->catalogItem[1]->varCode1, "LARGE");
- strcpy(myDMCB->catalogItem[1]->varCode2, "X-LARGE");
- myDMCB->catalogItem[1]->shUSA = 4;
- myDMCB->catalogItem[1]->shFOR = 10.50;
-
- strcpy(myDMCB->catalogItem[2]->name, "Upgrade from Testbed 0.9");
- // software upgrades have product codes that start with 8
- strcpy(myDMCB->catalogItem[2]->prodCode, "80003");
- myDMCB->catalogItem[2]->minPurchase = 1;
- myDMCB->catalogItem[2]->maxPurchase = 1;
- myDMCB->catalogItem[2]->price = 5;
- myDMCB->catalogItem[2]->numVarCodes = 0;
- myDMCB->catalogItem[2]->shUSA = 0;
- myDMCB->catalogItem[2]->shFOR = 0;
-
-
- // preselect items to be purchased
- // explanation: when the AutoPay module takes control of
- // the user interface, what items do you want to be preselected
- // for purchase by the user? If nothing, then set the following to 0.
-
- myDMCB->numItemsPrepurchased = 1;
-
- // Notice how the data structure of the preselected item precisely matches
- // the associated item in the product catalog. Please be careful and do
- // the same!
-
- // The only exception is the "editable" flag, which can be set to false
- // on a pre-selected item, even if the catalog doesn't match this. This
- // means the user won't be able to remove or edit this preselected item.
-
- strcpy(myDMCB->prepurchaseItem[0].name, "Register Testbed 1.0");
- strcpy(myDMCB->prepurchaseItem[0].prodCode, "90001");
- strcpy(myDMCB->prepurchaseItem[0].varCode, "");
- myDMCB->prepurchaseItem[0].price = 15.50;
- myDMCB->prepurchaseItem[0].quantity = 1;
- myDMCB->prepurchaseItem[0].editable = 1; // 1=true; 0=false
- myDMCB->prepurchaseItem[0].minPurchase = 1;
- myDMCB->prepurchaseItem[0].maxPurchase = 1;
- myDMCB->prepurchaseItem[0].shUSA=0;
- myDMCB->prepurchaseItem[0].shFOR=0;
-
- }
-
- /*
- Function: DoAutoPay
-
- Loads the AutoPay code resource into memory, and executes it. This works
- for PowerPC or 68K apps.
-
- Returns: Nothing
- */
-
- void DoAutoPay(digiMonBlock *dmiBlock)
- {
- UniversalProcPtr resProcUPP;
- ProcInfoType theProcInfo;
- Handle resHandle;
- OSErr result;
-
- resHandle = GetResource('CODE', 60);
- HLockHi(resHandle);
-
- #if defined(powerc) || defined (__powerc) || GENERATINGPOWERPC
-
- /*
- For PowerPC machines: The AutoPay resource is 68K, so if we're
- generating a PowerMac app call it from the Mixed Mode Manager
- */
- theProcInfo = kPascalStackBased | STACK_ROUTINE_PARAMETER
- (1, SIZE_CODE(sizeof(long)));
- resProcUPP = NewRoutineDescriptor((ProcPtr)*resHandle,
- theProcInfo, kM68kISA);
- CallUniversalProc(resProcUPP, theProcInfo, (long)dmiBlock);
- DisposeRoutineDescriptor(resProcUPP);
-
- #else
-
- /*
- For 68K machines, call it the old fashioned way
- */
- ((AutoPayCodePtr) *resHandle) ((long) dmiBlock);
-
-
- #endif
-
- HUnlock(resHandle);
- ReleaseResource(resHandle);
- }
-